﻿using NUnit.Framework;
using Raven.Client;
using Raven.Client.Embedded;

namespace Actya.IntegrationTests
{
	public abstract class InMemoryDocumentStoreTestCase
	{
		protected IDocumentStore DocumentStore { get; private set; }
		protected IDocumentSession Session { get; private set; }

		[SetUp]
		public void Init()
		{
			this.DocumentStore = NewInMemoryStore();
			this.Session = this.DocumentStore.OpenSession();
		}

		[TearDown]
		public void Shutdown()
		{
			if (this.Session != null)
			{
				this.Session.Dispose();
			}
			if (this.DocumentStore != null)
			{
				this.DocumentStore.Dispose();
			}
		}

		protected EmbeddableDocumentStore NewInMemoryStore()
		{
			var documentStore = new EmbeddableDocumentStore
			{
				RunInMemory = true
			};
			documentStore.Conventions.IdentityPartsSeparator = "-";
			documentStore.Initialize();
			return documentStore;
		}
	}
}
